package com.torry.workflow.service.web.controller;


import com.torry.workflow.api.wo.api.ProcessUserGroupApi;
import com.torry.workflow.api.wo.entity.ProcessUserGroup;
import com.torry.workflow.common.base.result.Result;
import io.swagger.models.auth.In;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/userGroup")
public class UserGroupController {

    @DubboReference
    private ProcessUserGroupApi processUserGroupApi;

    @PostMapping("saveUserGroup")
    public Result saveUserGroup(@RequestBody ProcessUserGroup userGroup) {
        if (userGroup.getId() == null) {
            processUserGroupApi.insertUserGroup(userGroup);
        } else {
            processUserGroupApi.updateUserGroup(userGroup);
        }
        return Result.saveSuccess();
    }


    @GetMapping("allUserGroup")
    public Result allUserGroup() {
        return Result.selectSuccess(processUserGroupApi.getAllUserGroups());
    }

    @GetMapping("getUsersByUserGroupId/{userGroupId}")
    public Result getUsersByUserGroupId(@PathVariable Integer userGroupId) {
        return Result.selectSuccess(processUserGroupApi.getUsersByUserGroupId(userGroupId));
    }
}
